(function() {
  define([], function() {
    'use strict';
    var DaoFactory;
    return DaoFactory = {
      registry: {},
      instanceCache: {},
      register: function(daoName, daoClass) {
        if (!_.has(this.registry, daoName)) {
          return this.registry[daoName] = daoClass;
        }
      },
      getDAOByName: function(daoName) {
        var instance;
        if (!_.has(this.registry, daoName)) {
          throw new Error("DAO with name " + daoName + " not found");
        }
        if (!_.contains(_.keys(this.instanceCache), daoName)) {
          this.instanceCache[daoName] = new this.registry[daoName];
          instance = this.instanceCache[daoName];
          instance.setBaseUrl(window.AppData.API_URL + instance.baseUrl);
        }
        return this.instanceCache[daoName];
      }
    };
  });

}).call(this);
